#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e4 + 10, M = N * 2;
int n, m, s, t;
struct node
{
	int a, b, w;
}S[M];
int p[N];
int cmp(node a, node b)
{
	return a.w < b.w;
}

int find(int x)
{
	if (x != p[x])p[x] = find(p[x]);
	return p[x];
}

bool check(int x)
{
	for (int i = 1; i <= n; i++)p[i] = i;
	for (int i = 1; i <= m; i++) {
		int v = S[i].w;
		if (v <= x) {
			int a1 = find(S[i].a);
			int b1 = find(S[i].b);
			if (a1 != b1) {
				p[a1] = b1;
			}
		}
	}
	if (find(s) == find(t))return 1;
	return 0;
}
//bool check(int x)
//{
//	for (int i = 1; i <= n; i++)p[i] = i;
//	
//	bool flag1 = 0, flag2 = 0;
//	int ma = 0;
//	for (int i = 1; i <= m; i++) {
//		if (S[i].a == s)flag1 = 1;
//		if (S[i].b == t)flag2 = 1;
//		ma = max(ma, S[i].w);
//		int a1 = find(S[i].a);
//		int b1 = find(S[i].b);
//		if (a1 != b1) {
//			p[a1] = b1;
//		}
//	}
//	if (flag1 && flag2 && ma == x)return 1;
//	return 0;
//}
int main()
{
	cin >> n >> m >> s >> t;
	int mi = 1e8, ma = 0;
	for (int i = 1; i <= m; i ++) {
		int a, b, w;
		cin >> a >> b >> w;
		mi = min(mi, w);
		ma = max(ma, w);
		S[i] = { a,b,w };
	}
	//sort(S + 1, S + m + 1, cmp);
	int l = mi - 1, r = ma + 1;
	while (l + 1 < r) {
		int mid = (l + r) >> 1;
		/*cout << "mid==" << mid << endl;
		cout << "l==" << l << endl;
		cout << "r==" << r << endl;*/
		if (check(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;	
	return 0;
}